
<!DOCTYPE html>
<html lang="zh-Hans" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Webpack Freestyle 之 Long Term Cache(webpack 实现持久性缓存) - 默默默默燃</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="TriDiamond Obsidian,"> 
    <meta name="description" content="一枚前端搬砖队队员的记录册,原文地址
How Browser Cache Works首先，我们要搞清楚浏览器缓存是怎么工作的。 那么，就让我画一张图来告诉大家吧，嘻嘻。


浏览器: 我需要 foo.js
服务器: 让我找找。,"> 
    <meta name="author" content="张白告丶"> 
    <link rel="alternative" href="atom.xml" title="默默默默燃" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    <link href="https://fonts.loli.net/css?family=Roboto+Mono|Rubik&display=swap" rel="stylesheet">
    
<link rel="stylesheet" href="//at.alicdn.com/t/font_1429596_nzgqgvnmkjb.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.7.2/animate.min.css">

    
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/codemirror.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/theme/dracula.css">

    
<link rel="stylesheet" href="/css/obsidian.css">

    
<link rel="stylesheet" href="/css/ball-atom.min.css">

<meta name="generator" content="Hexo 4.2.0"></head>


<body class="loading">
    <div class="loader">
        <div class="la-ball-atom la-2x">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <span id="config-title" style="display:none">默默默默燃</span>
    <div id="loader"></div>
    <div id="single">
    <div class="scrollbar gradient-bg-rev"></div>
<div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <div class="navigation animated fadeIn fast delay-1s">
        <img id="home-icon" class="icon-home" src="/img/favicon.png" alt="" data-url="https://zhanghao-web.github.io">
        <div id="play-icon" title="Play/Pause" class="iconfont icon-play"></div>
        <h3 class="subtitle">Webpack Freestyle 之 Long Term Cache(webpack 实现持久性缓存)</h3>
        <div class="social">
            <!--        <div class="like-icon">-->
            <!--            <a href="javascript:;" class="likeThis active"><span class="icon-like"></span><span class="count">76</span></a>-->
            <!--        </div>-->
            <div>
                <div class="share">
                    
                        <a href="javascript:;" class="iconfont icon-share1"></a>
                        <div class="share-component-cc" data-disabled="facebook,douban,linkedin,diandian,tencent,google"></div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

    <div class="section">
        <div class=article-header-wrapper>
    <div class="article-header">
        <div class="article-cover animated fadeIn" style="
            animation-delay: 600ms;
            animation-duration: 1.2s;
            background-image: 
                radial-gradient(ellipse closest-side, rgba(0, 0, 0, 0.65), #100e17),
                url(/img/cover.jpg) ">
        </div>
        <div class="else">
            <p class="animated fadeInDown">
                
                <a href="/categories/Tools"><b>「
                    </b>TOOLS<b> 」</b></a>
                
                July 31, 2019
            </p>
            <h3 class="post-title animated fadeInDown"><a href="/2019/07/31/Tools/Webpack-Freestyle-%E4%B9%8B-Long-Term-Cache-webpack-%E5%AE%9E%E7%8E%B0%E6%8C%81%E4%B9%85%E6%80%A7%E7%BC%93%E5%AD%98/" title="Webpack Freestyle 之 Long Term Cache(webpack 实现持久性缓存)" class="">Webpack Freestyle 之 Long Term Cache(webpack 实现持久性缓存)</a>
            </h3>
            
            <p class="post-count animated fadeInDown">
                
                <span>
                    <b class="iconfont icon-text2"></b> <i>Words count</i>
                    15k
                </span>
                
                
                <span>
                    <b class="iconfont icon-timer__s"></b> <i>Reading time</i>
                    14 mins.
                </span>
                
                
                
                <span id="busuanzi_container_page_pv">
                    <b class="iconfont icon-read"></b> <i>Read count</i>
                    <span id="busuanzi_value_page_pv">0</span>
                </span>
                
            </p>
            
            
            <ul class="animated fadeInDown post-tags-list" itemprop="keywords"><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/Webpack/" rel="tag">Webpack</a></li></ul>
            
        </div>
    </div>
</div>

<div class="screen-gradient-after">
    <div class="screen-gradient-content">
        <div class="screen-gradient-content-inside">
            <div class="bold-underline-links screen-gradient-sponsor">
                <p>
                    <span class="animated fadeIn delay-1s"></span>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="article">
    <div class='main'>
        <div class="content markdown animated fadeIn">
            <p><a href="https://zhuanlan.zhihu.com/p/27710902" target="_blank" rel="noopener">原文地址</a></p>
<h2 id="How-Browser-Cache-Works"><a href="#How-Browser-Cache-Works" class="headerlink" title="How Browser Cache Works"></a>How Browser Cache Works</h2><p>首先，我们要搞清楚浏览器缓存是怎么工作的。 那么，就让我画一张图来告诉大家吧，嘻嘻。</p>
<p><img src="https://pic2.zhimg.com/80/v2-5babc40038bcc8add9c5f8bcb717c7b5_hd.png" alt="pic"></p>
<ul>
<li>浏览器: 我需要 foo.js</li>
<li>服务器: 让我找找。找到了，给你，缓存有效期为 1 年。</li>
<li>浏览器: 好，我把他缓存到磁盘里。</li>
</ul>
<p>过了 2 天，</p>
<p><img src="https://pic4.zhimg.com/80/v2-b5e4a95482e0008758b94ec96c0f60a3_hd.png" alt="pic1"></p>
<p>浏览器: 我需要 foo.js ，在缓存里找到了。缓存还有效，那直接读缓存。<br>用户：哇塞，这网页秒开啊。</p>
<p>又过了 2 天，foo.js 的代码更新了。（内容从 Hello world 变成了 Goodbye world ）</p>
<p><img src="https://pic2.zhimg.com/80/v2-680f699d7e09991af4f6bf260559aef1_hd.png" alt="pic2"></p>
<p>浏览器：我需要 foo.js ，在缓存里找到了。缓存还有效，那直接读缓存。<br>产品经理：？？？这页面怎么跟以前一样啊？</p>
<p>很尴尬。foo.js 明明更新了，但是浏览器还是读取在缓存中旧的 foo.js ，原因是我们用了缓存，不用缓存就没这事儿了。?</p>
<p>解决办法嘛，当然有的。比如每次利用缓存之前，<code>先向服务器确认文件是否有更新，有更新则使用新的否则读缓存</code>。还有一种方法是<code>把缓存破坏掉，也就是下面要说的*Cache Busting Technique*</code> </p>
<h2 id="Cache-Busting-Technique"><a href="#Cache-Busting-Technique" class="headerlink" title="Cache Busting Technique"></a>Cache Busting Technique</h2><p>因为 foo.js 的代码变化了，但是他的缓存还没失效，此时浏览器还是会读取以前的缓存了的 foo.js ，并不会去服务器下载最新的。这显然不是我们想要的，怎么办呢？我们需要破坏缓存（ Cache Busting ）。</p>
<p>破坏缓存并不是禁止缓存，而是换一种方式让缓存失效。比如：</p>
<p>1.修改文件的名字：foo.js -&gt; foo.v2.js<br>2.修改文件的路径：/static/foo.js -&gt; /static/v2/foo.js<br>3.加 query string : foo.js -&gt; foo.js?v=qwer</p>
<p>我们下面将采用第一种方法，也就是修改文件的名字。我们把更新后的 foo.js 的文件名改成 foo.v2.js 。这样，浏览器就不会去读取缓存里的旧的 foo.js ，而是向服务请请求 foo.v2.js ，如下图所示：</p>
<p><img src="https://pic2.zhimg.com/80/v2-103471cbe5d028bc9e1122db6e4243b9_hd.png" alt="pic4"></p>
<p>那么，假设我们现在有很多很多的静态文件，然后每次需要更新很多很多的文件，那是不是要手动地一个一个地修改文件的名字呢？我们的理想当然是：哪个文件更新了，就<strong>自动</strong>地生成一个新的文件名。</p>
<p>另外，如果我们打包出来的静态文件只有一个单独的 JavaScript 文件 app.js ，那么每次改动一点代码，app.js 的文件名肯定都会变。但实际上，我只改动了某个模块的代码（其他模块并没有修改），就破坏了其他模块的缓存，这显然没有充分利用到缓存啊。我们的想法是：哪个模块更新了破坏他的缓存，没更新的模块继续利用缓存。</p>
<p>这个时候，我们就需要用到 webpack 的 code splitting（如果还不会的话，可以阅读 <a href="https://zhuanlan.zhihu.com/p/26710831?refer=ElemeFE" target="_blank" rel="noopener">Webpack 大法之 Code Splitting</a> ）。把整个 App 分成一个个 chunk ，然后哪个 chunk 发生改变，我就破坏他的缓存；没有更新的 chunk ，则继续利用缓存。这样一来，我们就把缓存的作用发挥到淋漓尽致～</p>
<p>所以，<code>code splitting</code> 的作用除了”减少文件大小”之外，还能更充分地利用缓存。所以，下面就让我们用 webpack 来实现持久性缓存吧。</p>
<h2 id="Webpack-amp-Caching"><a href="#Webpack-amp-Caching" class="headerlink" title="Webpack &amp; Caching"></a>Webpack &amp; Caching</h2><p>首先，把我们的 <a href="https://link.zhihu.com/?target=https%3A//github.com/lyyourc/webpack-code-splitting-demo">demo 项目</a>（已经实现了 code splitting ）下载并安装好依赖。</p>
<p>接着，修改 webpack 配置文件，给我们打包后的静态文件生成随机的唯一的名字。（ changed files ）</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// webpack.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  output: &#123;</span><br><span class="line">    <span class="comment">//...</span></span><br><span class="line">    filename: <span class="string">'[name].[chunkhash:8].js'</span>,</span><br><span class="line">    chunkFilename: <span class="string">'[name].[chunkhash:8].chunk.js'</span>,</span><br><span class="line">    <span class="comment">//...</span></span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>我们使用了 <code>[chunkhash]</code> 这个占位符，并且为了更好地分辨和展示 demo ，我们截取了他的前 8 个字符 <code>[chunkhash:8]</code>，但是在实际生产中我们不要那么做！</p>
<p>好咯，现在来看看我们的打包后的文件：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">                    Asset            Size    Chunk Names</span><br><span class="line">common-<span class="keyword">in</span>-lazy.fa79d198.chunk.js    <span class="number">11.6</span> kB  common-<span class="keyword">in</span>-lazy</span><br><span class="line">    used-twice.c2c4927c.chunk.js    <span class="number">17.1</span> kB  used-twice</span><br><span class="line">        Photos<span class="number">.28</span>d663ec.chunk.js    <span class="number">8.57</span> kB  Photos</span><br><span class="line">         Emoji.d3ea8991.chunk.js    <span class="number">1.15</span> kB  Emoji</span><br><span class="line">                 app<span class="number">.724</span>a238a.js    <span class="number">2.53</span> kB  app</span><br><span class="line">              vendor<span class="number">.05</span>be8f94.js     <span class="number">104</span> kB  vendor</span><br></pre></td></tr></table></figure>
<p>那么，现在我们来修改一下 App.vue ，添加个 <code>&lt;footer&gt;</code> 标签（ changed files ） :</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- old codes --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">footer</span>&gt;</span> A Footer <span class="tag">&lt;/<span class="name">footer</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p>此时的打包变成了：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">                        Asset       Size  Chunk Names</span><br><span class="line">common-<span class="keyword">in</span>-lazy.fa79d198.chunk.js    <span class="number">11.6</span> kB  common-<span class="keyword">in</span>-lazy</span><br><span class="line">    used-twice.c2c4927c.chunk.js    <span class="number">17.1</span> kB  used-twice</span><br><span class="line">        Photos<span class="number">.28</span>d663ec.chunk.js    <span class="number">8.57</span> kB  Photos</span><br><span class="line">         Emoji.d3ea8991.chunk.js    <span class="number">1.15</span> kB  Emoji</span><br><span class="line">                 app.fdc2eedb.js    <span class="number">2.57</span> kB  app</span><br><span class="line">              vendor.b611a5da.js     <span class="number">104</span> kB  vendor</span><br></pre></td></tr></table></figure>
<p>注意到，我们的 app chunk 的 hash 从 724a238a 变成了 fdc2eedb ，这是我们所希望看到的东西。但是，与此同时 vendor chunk 的 hash 也变了（05be8f94 -&gt; b611a5da）。然而，我们并没有修改 vendor chunk 的代码，为什么他的 hash 也变了呢？?</p>
<p>原因是 <code>vendor chunk</code> 里面包含了 <code>webpack</code> 的 <code>runtime</code> 代码（用来解析和加载模块之类的运行时代码）：</p>
<p>解决办法就是把 webpack 的 runtime 代码提取出来（ changed files ）：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> webpack.optimize.CommonsChunkPlugin(&#123; </span><br><span class="line">  name: [<span class="string">'manifast'</span>] </span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>
<p>把之前 App.vue 更新了的代码暂时去掉，也就是上面添加的 <code>&lt;footer&gt;</code> 标签去掉：</p>
<p>接着按照之前的，修改 App.vue ，添加 `` 标签（ changed files ）：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- old codes --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">footer</span>&gt;</span> A Footer <span class="tag">&lt;/<span class="name">footer</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>而此时的打包：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">                        Asset       Size  Chunk Names</span><br><span class="line">common-<span class="keyword">in</span>-lazy.fa79d198.chunk.js    <span class="number">11.6</span> kB  common-<span class="keyword">in</span>-lazy</span><br><span class="line">    used-twice.c2c4927c.chunk.js    <span class="number">17.1</span> kB  used-twice</span><br><span class="line">        Photos<span class="number">.28</span>d663ec.chunk.js    <span class="number">8.57</span> kB  Photos</span><br><span class="line">         Emoji.d3ea8991.chunk.js    <span class="number">1.15</span> kB  Emoji</span><br><span class="line">                 app.fdc2eedb.js    <span class="number">2.57</span> kB  app</span><br><span class="line">              vendor<span class="number">.3</span>b70f9d8.js     <span class="number">103</span> kB  vendor</span><br><span class="line">            manifast<span class="number">.1442e3</span>f3.js    <span class="number">1.54</span> kB  manifast</span><br></pre></td></tr></table></figure>
<p>很开心，此时只有 <code>app.js</code> 和 <code>manifast.js</code> 这 2 个 chunk 的文件名的 hash 发生了改变，vendor.js chunk 和其他 chunk 都没变，舒服。</p>
<p>但是，假如我们给 App.vue 随便引入一个模块的话，比如（ changed files ）：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;script&gt;</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line"><span class="keyword">import</span> noop <span class="keyword">from</span> <span class="string">'./shared/utils.js'</span></span><br><span class="line">&lt;<span class="regexp">/script&gt;</span></span><br></pre></td></tr></table></figure>
<p>而此时的打包：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">                        Asset       Size  Chunk Names</span><br><span class="line">common-<span class="keyword">in</span>-lazy<span class="number">.30</span>b1e9b6.chunk.js    <span class="number">11.6</span> kB  common-<span class="keyword">in</span>-lazy</span><br><span class="line">    used-twice<span class="number">.9</span>eccbe5a.chunk.js    <span class="number">17.1</span> kB  used-twice</span><br><span class="line">        Photos<span class="number">.6096611</span>c.chunk.js    <span class="number">8.57</span> kB  Photos</span><br><span class="line">         Emoji<span class="number">.6208</span>da60.chunk.js    <span class="number">1.15</span> kB  Emoji</span><br><span class="line">                 app<span class="number">.4675</span>a374.js    <span class="number">2.61</span> kB  app</span><br><span class="line">              vendor<span class="number">.8</span>b538297.js     <span class="number">103</span> kB  vendor</span><br><span class="line">            manifast<span class="number">.25580296</span>.js    <span class="number">1.54</span> kB  manifast</span><br></pre></td></tr></table></figure>
<p>卧槽居然所有 chunk 的 hash 都发生了改变，这是为什么？</p>
<p><strong>原因是在 webpack 里每个模块都有一个 module id </strong>，module id 是该模块在<a href="https://link.zhihu.com/?target=https%3A//webpack.js.org/concepts/dependency-graph/">模块依赖关系图</a>里按顺序分配的序号，如果这个 module id 发生了变化，那么他的 chunkhash 也会发生变化。（不确定这里是否正确，希望大佬指出错误）</p>
<p><img src="https://pic4.zhimg.com/80/v2-5a4b6bef5809e00512873d481a3670e7_hd.png" alt="pic5"></p>
<p>所以呢，我们需要用一种新的方式来计算 module id 。 <strong>HashedModuleIdsPlugin</strong> 这个插件，他是根据模块所在路径来映射其 module id ，这样就算引入了新的模块，也不会影响 module id 的值，只要模块的路径不改变的话。</p>
<p>修改我们的 webpack 配置。并且，去掉上面 App.vue 引入的 noop 模块。（ changed files ）</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// webpack.config.js</span></span><br><span class="line"></span><br><span class="line">plugins: [</span><br><span class="line">  <span class="keyword">new</span> webpack.HashedModuleIdsPlugin(),</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">],</span><br></pre></td></tr></table></figure>
<p>可以看到，只有 app chunk 和 manifast chunk 的 hash 发生了改变，其他 chunk 不变所以他们的缓存就没被破坏。</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>用 webpack 实现 long term cache ：</p>
<ul>
<li>生成稳定的 hash 文件名</li>
<li>提取 webpack 的 runtime 代码</li>
<li>code splitting</li>
</ul>
<p>还有一些东西我们是没讲到的，比如 CSS 的 cache ，内联 manifast chunk 等等，就留给大家去探索咯。</p>
<p>最后需要注意的是，webpack 是允许其他 plugin 来修改 chunkhash 的，如果他们不能正确地处理的话，那么，假设你更新了代码，但是对应的 chunkhash 没变，并且此时缓存还没失效，就会导致线上的代码还是旧的，用户看到的还是以前的页面。因此，一定要特别注意 chunkhash 到底正不正确！！</p>
<p>希望本文可以帮助到大家，这样我会很开心的。(<em> </em>)</p>

            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls"
                data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
            <ul id="audio-list" style="display:none">
                
                
                <li title='0' data-url='/statics/chengdu.mp3'></li>
                
                    
            </ul>
            
            
            
    <div id='gitalk-container' class="comment link"
        data-ae='true'
        data-ci='ec894e2b66f752e8b7fb'
        data-cs='3ccc2e92bb350688fe2c2dc2930189b62622bfb1'
        data-r='blog-comments'
        data-o='TriDiamond'
        data-a='TriDiamond'
        data-d='undefined'
    >Comments</div>


            
            
        </div>
        <div class="sidebar">
            <div class="box animated fadeInRight">
                <div class="subbox">
                    <img src="https://res.cloudinary.com/tridiamond/image/upload/v1573019751/TriDiamond_logo_ui_xeublz.jpg" height=300 width=300></img>
                    <p>张白告丶</p>
                    <span>Think like an artist, develop like an artisan</span>
                    <dl>
                        <dd><a href="https://github.com/zhanghao-web" target="_blank"><span
                                    class=" iconfont icon-github"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-twitter"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-stack-overflow"></span></a></dd>
                    </dl>
                </div>
                <ul>
                    <li><a href="/">149 <p>Articles</p></a></li>
                    <li><a href="/categories">23 <p>Categories</p></a></li>
                    <li><a href="/tags">47 <p>Tags</p></a></li>
                </ul>
            </div>
            
            
            
            <div class="box sticky animated fadeInRight faster">
                <div id="toc" class="subbox">
                    <h4>Contents</h4>
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#How-Browser-Cache-Works"><span class="toc-number">1.</span> <span class="toc-text">How Browser Cache Works</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Cache-Busting-Technique"><span class="toc-number">2.</span> <span class="toc-text">Cache Busting Technique</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Webpack-amp-Caching"><span class="toc-number">3.</span> <span class="toc-text">Webpack &amp; Caching</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
                </div>
            </div>
            
            
        </div>
    </div>
</div>

    </div>
</div>
    <div id="back-to-top" class="animated fadeIn faster">
        <div class="flow"></div>
        <span class="percentage animated fadeIn faster">0%</span>
        <span class="iconfont icon-top02 animated fadeIn faster"></span>
    </div>
</body>
<footer>
    <p class="copyright" id="copyright">
        &copy; 2020
        <span class="gradient-text">
            张白告丶
        </span>.
        Powered by <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a>
        Theme
        <span class="gradient-text">
            <a href="https://github.com/TriDiamond/hexo-theme-obsidian" title="Obsidian" target="_blank" rel="noopener">Obsidian</a>
        </span>
        <small><a href="https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/CHANGELOG.md" title="v1.4.3" target="_blank" rel="noopener">v1.4.3</a></small>
    </p>
</footer>

<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
  MathJax.Hub.Config({
    "HTML-CSS": {
      preferredFont: "TeX",
      availableFonts: ["STIX", "TeX"],
      linebreaks: {
        automatic: true
      },
      EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
      inlineMath: [
        ["$", "$"],
        ["\\(", "\\)"]
      ],
      processEscapes: true,
      ignoreClass: "tex2jax_ignore|dno",
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      noUndefined: {
        attributes: {
          mathcolor: "red",
          mathbackground: "#FFEEEE",
          mathsize: "90%"
        }
      },
      Macros: {
        href: "{}"
      }
    },
    messageStyle: "none"
  });
</script>
<script>
  function initialMathJax() {
    MathJax.Hub.Queue(function () {
      var all = MathJax.Hub.getAllJax(),
        i;
      // console.log(all);
      for (i = 0; i < all.length; i += 1) {
        console.log(all[i].SourceElement().parentNode)
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  }

  function reprocessMathJax() {
    if (typeof MathJax !== 'undefined') {
      MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    }
  }
</script>



    
<link rel="stylesheet" href="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.css">

    
<script src="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.js"></script>



<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/obsidian.js"></script>
<script src="/js/jquery.truncate.js"></script>
<script src="/js/search.js"></script>


<script src="//cdn.bootcss.com/typed.js/2.0.10/typed.min.js"></script>


<script src="//cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>


<script src="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>


<script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.min.js"></script>

    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/javascript/javascript.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/css/css.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/xml/xml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/clike/clike.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/php/php.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/shell/shell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/python/python.min.js"></script>




    
<script src="/js/busuanzi.min.js"></script>

    <script>
        $(document).ready(function () {
            if ($('span[id^="busuanzi_"]').length) {
                initialBusuanzi();
            }
        });
    </script>



<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/default-skin/default-skin.min.css">


<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="//www.googletagmanager.com/gtag/js?id=UA-149874671-1"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'UA-149874671-1');
    </script>





<script>
    function initialTyped () {
        var typedTextEl = $('.typed-text');
        if (typedTextEl && typedTextEl.length > 0) {
            var typed = new Typed('.typed-text', {
                strings: ["Think like an artist, develop like an artisan", "艺术家思维去思考问题，工匠创造精神去开发"],
                typeSpeed: 90,
                loop: true,
                loopCount: Infinity,
                backSpeed: 20,
            });
        }
    }

    if ($('.article-header') && $('.article-header').length) {
        $(document).ready(function () {
            initialTyped();
        });
    }
</script>




</html>
